import 'package:car_controller/widget/text_widget.dart';
import 'package:flutter/material.dart';
import 'package:car_controller/theme/app_theme.dart';

class CarPart extends StatelessWidget {
  final bool state;
  final String name;
  final VoidCallback onTap;
  const CarPart(
      {super.key,
      required this.state,
      required this.name,
      required this.onTap});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(AppTheme.defaultPadding / 3),
      height: 150,
      width: 160,
      decoration: AppTheme.cardDecoration(state),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
            flex: 4,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                text(name, AppTheme.subheadingFontSize,
                    AppTheme.textPrimaryColor, FontWeight.bold),
                const SizedBox(height: 10),
                text(state ? "已开启" : "已关闭", AppTheme.bodyFontSize,
                    AppTheme.textSecondaryColor, FontWeight.bold),
              ],
            ),
          ),
          Transform.rotate(
            angle: -1.6,
            child: Transform.scale(
              scaleX: 1.0,
              scaleY: 1.0,
              child: Switch(
                activeColor: AppTheme.primaryColor,
                activeTrackColor: AppTheme.textPrimaryColor,
                inactiveTrackColor: AppTheme.textSecondaryColor,
                value: state,
                onChanged: (value) => onTap(),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
